package top.archiesean.id.service.impl;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.archiesean.id.service.IId;
import top.archiesean.id.utils.SnowflakeId;

import java.util.List;

/**
 * @author ArchieSean
 * @description id
 * @date 2024-01-13 08:29
 */
@Service
@Slf4j
public class IdImpl implements IId {
    /**
     * 生成id
     *
     * @return id
     */
    @Override
    public Long getId() {
        return SnowflakeId.createId();
    }

    /**
     * 批量生成id
     *
     * @param num id
     * @return list
     */
    @Override
    public List<Long> getId(int num) {
        List<Long> list = Lists.newArrayList();
        if (num <= 0) {
            log.info("当前传入的需要生成id的数量为：{},不予生成", num);
            return list;
        }
        for (int i = 0; i < num; i++) {
            list.add(SnowflakeId.createId());
        }
        return Lists.newCopyOnWriteArrayList(list);
    }
}
